﻿using System;

namespace Epitech.Krisk.Kinect.Sensor.Gestures.Swipes
{
    public class RightHandSwipe : SwipeGestureDetector
    {

        private static RightHandSwipe _instance;
        public static RightHandSwipe Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new RightHandSwipe();
                return _instance;
            }
        }

        public RightHandSwipe(int numberOfGestureAnalyzed = 20, int minimalPeriodBetweenGesture = 0)
            : base(numberOfGestureAnalyzed, minimalPeriodBetweenGesture)
        {
        }

        protected override void LookForGesture()
        {

            // Swipe to top
            if (ScanPositions((p1, p2) => Math.Abs(p2.X - p1.X) < SwipeMaximalHeight, // Height
                              (p1, p2) => p2.Y - p1.Y > -0.01f, // Progression to top
                              (p1, p2) => Math.Abs(p2.Y - p1.Y) > SwipeMinimalLengthV, // Length
                              SwipeMininalDuration, SwipeMaximalDuration)) // Duration
            {
                RaiseGestureDetected(GestureType.SwipeToTop);
                return;
            }

            // Swipe to bottom
            if (ScanPositions((p1, p2) => Math.Abs(p2.X - p1.X) < SwipeMaximalHeight, // Height
                              (p1, p2) => p2.Y - p1.Y < 0.01f, // Progression to top
                              (p1, p2) => Math.Abs(p2.Y - p1.Y) > SwipeMinimalLengthV, // Length
                              SwipeMininalDuration, SwipeMaximalDuration)) // Duration
            {
                RaiseGestureDetected(GestureType.SwipeToBottom);
            }


            // Swipe to Left
            if (ScanPositions((p1, p2) => Math.Abs(p2.Y - p1.Y) < SwipeMaximalHeight, // Height
                              (p1, p2) => p2.X - p1.X < 0.01f, // Progression to left
                              (p1, p2) => Math.Abs(p2.X - p1.X) > SwipeMinimalLengthH, // Length
                              SwipeMininalDuration, SwipeMaximalDuration)) // Duration
            {
                //check if two movement are not to close
                TimeSpan timetemp = DateTime.Now - _lastMove;
                if (timetemp.Seconds < TimeBetweenMovement)
                {
                    _lastMove = DateTime.Now;
                    return;
                }
                RaiseGestureDetected(GestureType.SwipeToleft);
                return;
            }
        }

    }
}